package com.example.dragandview.http.adaptar;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.dragandview.R;
import com.example.dragandview.http.model.Wxarticle;

import java.util.ArrayList;
import java.util.List;

public class WxarticleAdaptar extends RecyclerView.Adapter<WxarticleAdaptar.InnerAdapter>{

    private List<Wxarticle.DataBean> mData = new ArrayList<>();
    @NonNull
    @Override
    public InnerAdapter onCreateViewHolder(@NonNull ViewGroup parent,int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.wxarticle_item,parent,false);
        return new InnerAdapter(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull InnerAdapter holder, int position) {
        View itemView = holder.itemView;
        TextView tv_wxarticle_id = itemView.findViewById(R.id.tv_wxarticle_id);
        TextView tv_wxarticle_name = itemView.findViewById(R.id.tv_wxarticle_name);
        TextView tv_wxarticle_order = itemView.findViewById(R.id.tv_wxarticle_order);
        Wxarticle.DataBean contentBean = mData.get(position);
        String id = String.valueOf(contentBean.getId());
        String name = contentBean.getName();
        String order = String.valueOf(contentBean.getOrder());
        tv_wxarticle_id.setText(id);
        tv_wxarticle_name.setText(name);
        tv_wxarticle_order.setText(order);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void setData(Wxarticle result) {
        mData.clear();
        mData.addAll(result.getData());
        notifyDataSetChanged();
    }

    public class InnerAdapter extends RecyclerView.ViewHolder {
        public InnerAdapter(@NonNull View itemView) {
            super(itemView);
        }
    }
}
